<%
    /**
     * 定制显示属性
     *
     * created by amon 2005-12-21
     */
%>
<%@ include file = "/common/ini.jsp"%>
<%@ include file = "/common/_log4j.jsp"%>
<%@ include file = "/common/_ApplicationContext_init.jsp"%> 
<%@ include file = "/common/_currUser_Infor.jsp"%>
<%@ include file = "/common/params/_getParamsInSession.jsp"%>
<%@ include file = "/common/params/iniParamsForm.jsp"%>
<% String configUrl = "/common/List/_configColumn/configWinXPStyle.jsp";%>
<%@ include file = "/common/List/_configColumn/getTitleAndList.jsp"%>
<%@ include file = "/js/_js_for_select.jsp"%>
<%@ include file = "/js/_js_for_checkbox.jsp"%>
<%@ include file = "/css/detailcss.jsp"%>
<%@ include file = "/common/_vr.jsp"%>
<%
    if(!vr.isAllValidated())    
    {
        %>
        <font color="red">userId<%= vr.getErrMess("userId")%></font>
        <font color="red">configedServiceURL<%= vr.getErrMess("configedServiceURL")%></font>
        <font color="red">columnSort<%= vr.getErrMess("columnSort")%></font>
        <%
        return;
    }    
    String userId = currUser.getId();
%>
<%
    logger.info("开始获取serviceURL" );
    String serviceURL = ((String[])paramsMap.get("serviceURL"))[0];
    ConfigColumnManager configColumnManager = (ConfigColumnManager)applicationContext.getBean("configColumnManager");
    ConfigColumn configColumn;
    if(configColumnManager.getByUserIdAndServiceURL(userId,serviceURL) == null)
    {
        configColumn = null;
    }
    else
    {
        configColumn = (ConfigColumn)configColumnManager.getByUserIdAndServiceURL(userId,serviceURL);
    }
    
%>
<title>定制列</title>
<script>
    function insert()
    {
        try
        {
            addSelected2OtherSelector(ccForm.defaultColumn,ccForm.configColumn);
            selectNone(ccForm.defaultColumn);
        }
        catch(err)
        {
            alert(err);
        }
    }

    function del()
    {
        delSelectedOption(ccForm.configColumn);
    }

    function insertAll()
    {
        selectAll(ccForm.defaultColumn);
        insert();
    }

    function removeAll()
    {
        selectAll(ccForm.configColumn);
        delSelectedOption(ccForm.configColumn);
    }
</script>
<link rel="stylesheet" href="<%= request.getContextPath()%>/css/os.css" type="text/css">
<table width="100%" height="100%">
<form name="ccForm" method="post" action="<%= ControllerURL%>">
<%
        // 初始化所有字段框
        logger.debug("初始化所有字段框");
        ItemTitleArea itArea = (ItemTitleArea)request.getAttribute("viewer");
        List titles = itArea.getTitles(request.getContextPath());
        int index = 0;
        for(int i = 0; i < titles.size(); i ++)
        {
            Title title = (Title)titles.get(i);
            int sumOfLeafs = title.getSumOfLeafs();
            if(sumOfLeafs == 0)
            {
                sumOfLeafs = 1;
            }
            StringBuffer sb = new StringBuffer(sumOfLeafs * 2);
            // 标题的index
            sb.append(i)
              .append("_");
            // 栏目的index
            for(int j = 0; j < sumOfLeafs; j ++)
            {
                sb.append(index)
                  .append("-");
                index ++;
            }// for
            String str = sb.toString();
            str = str.substring(0,str.length() - 1);
            %>
    <tr bgcolor="F2F2F2" >
        <td align="left" >
            <input type="checkbox" id="cc_<%= str%>" name="configColumn" value="<%= str%>">        
            <%= title.getName()%>
        </td>
    </tr>
                
            <%
        } // 初始化所有字段框for
%>
    <tr  >
        <td align="left" onclick="gotoConfigColumn()">
            &nbsp;&nbsp;&nbsp;&nbsp;<B><a href="#" >全部...</a></B></a>
        </td>
    </tr>
    <input type="hidden" name="serviceURL" >
    <input type="hidden" name="configedServiceURL" >
    <input type="hidden" name="columnSort" >
    <input type="hidden" name="titleSort" >
    <input type="hidden" name="userId" >
    <input type="hidden" name="id" >
</form>
    <tr>
        <td align="center">
            <input type="button" value="提交" onclick="save()">&nbsp;
            <input type="button" value="重置" onclick="reset()">&nbsp;
            <input type="button" value="返回" onclick="window.close()">
        </td>
    </tr>
</table>
<script>
    function gotoConfigColumn()
    {
        opener.configColumn();
        window.close();
    }
    function save()
    {
        if(!hasChecked(ccForm,"configColumn"))
        {
            window.close();
        }
        else
        {
            ccForm.columnSort.value = "";
            ccForm.titleSort.value = "";
            for(var i = 0; i < ccForm.tags('INPUT').length; i ++)
            {
                if(ccForm.tags('INPUT')[i].type == "checkbox" 
                && ccForm.tags('INPUT')[i].name == "configColumn"
                && ccForm.tags('INPUT')[i].checked)
                {
                    var strs = ccForm.tags('INPUT')[i].value.split("_");
                    if(strs.length != 2)
                    {
                        alert("定制列标题和记录列下标号解析失败");
                        return;
                    }
                    ccForm.titleSort.value = ccForm.titleSort.value + "," +strs[0];
                    ccForm.columnSort.value = ccForm.columnSort.value + "," +strs[1];
                }
            }
            ccForm.titleSort.value = ccForm.titleSort.value.substring(1,ccForm.titleSort.value.length);
            ccForm.columnSort.value = ccForm.columnSort.value.substring(1,ccForm.columnSort.value.length);
            ccForm.submit();
        }
    }

    function reset()
    {
        setAllCheckedOrUnChekced(ccForm,"configColumn",false);
        try
        {
            ccForm.configedServiceURL.value = queryForm.serviceURL.value;
            <%
            if(configColumn == null)
            {
            %>
            ccForm.serviceURL.value = "userdefined.configcolumn.NewConfigColumnService";
            <%
            } //
            else
            {
            %>
            ccForm.serviceURL.value = "userdefined.configcolumn.UpdateConfigColumnService";
            ccForm.id.value = "<%= configColumn.getId()%>";
            // 初始化默认栏目
            try
            {
            <%
                String[] titleSorts =  configColumn.getTitleSorts();
                String[] titleValues = configColumn.getTitleSortsValues();
                for(int i = 0; i < titleValues.length; i ++)
                {
                    String titleValue = titleSorts[i] + "_" + titleValues[i];
                    %>  
                    ccForm.cc_<%= titleValue%>.checked = true;
                    <%
                }// for
            %>
            }//js try
            catch(err)
            {
                alert("原来定义的字段已经发生变更,请重新定义");
            }// js catch
            <%
            }//else
            %>
            ccForm.userId.value = "<%= userId%>";
        }
        catch(err)
        {
            alert(err);
        }
    }
    this.reset();
</script>
